
package vader.config;
import com.google.protobuf.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

/**
 * @author kaivader
 */
@Component
@Slf4j
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {



    private static final String XHS_NOTE_DETAIL = "http://whosecard.com:8081/api/xiaohongshu/note/detail?note_id=";
    private static final String WHOSECARD_KEY = "&key=a5f2a49e4a9b85a029415650818ce1deca668d2975e073877070e210";


    public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    /**
     * 针对redis数据失效事件，进行数据处理
     * 根据redis key值的失效事件，处理当天未完成的app商业任务
     *
     * @param message 键名
     * @param pattern 字符
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        // 用户做自己的业务处理即可,注意message.toString()可以获取失效的key
        String expiredKey = message.toString();
        String addContentPrefix = "content:article:file";

        if (expiredKey.startsWith(addContentPrefix)) {
            String[] expiredKeys = expiredKey.split(":");
            if (expiredKeys.length > 1) {
                String articleId = expiredKeys[4];
                Long merchantId = Long.valueOf(expiredKeys[3]);
                Integer times = Integer.valueOf(expiredKeys[5]);

                String key = "article_file_upload" + articleId;
                RLock lock = redissonClient.getLock(key);
                if (lock.tryLock()) {


                }
            }
        }
    }
}